/**
 * 所属节点：启用流程引导列表
 * 创建人：chen
 * 创建时间：2024年8月29日
 * 最后修改人：chen
 */
cb.define(process.env.__DOMAINKEY__, function() {
	let GDGY01_isv_appconfigInit_VM_Extend = {
		doAction: function(name, viewModel) {
			if (this[name]) this[name](viewModel);
		},
		init: function(viewModel) {
			let tenantID = viewModel.getAppContext().tenant.tenantId;
			let userInfo = viewModel.getAppContext().user;
			const qianzhui = "/gdgy/pc/isv2";

			viewModel.on("customInit", function(data) {
				//启用流程引导--页面初始化
			});

			function AutoDataWork(url, reqParams, callback) {
				const proxy = viewModel.setProxy({
					inithttp: {
						url: qianzhui + url + "?tenant_id=" + tenantID + "&userId=" + userInfo.userId,
						method: "POST",
					},
				});
				proxy.inithttp(reqParams, callback);
			}

			function AutoDataWorkSync(url, reqParams) {
				const proxy = viewModel.setProxy({
					inithttp: {
						url: qianzhui + url + "?tenant_id=" + tenantID + "&userId=" + userInfo.userId,
						method: "POST",
					},
				});
				return proxy.inithttpSync(reqParams);
			}


			viewModel.get("button6ef") && viewModel.get("button6ef").on("click", function(data) {
					// 初始化组织权限--单击
					let reqParams = {};
					const urlAPI = "/autodata/OrgunitEntityAuto";
					let rest = AutoDataWorkSync(urlAPI, reqParams);
					if (rest == null) {
						cb.utils.alert("网络异常，请稍后重试");
						return false;
					}
					if (rest.status != 1) {
						cb.utils.alert(rest.message);
						return false;
					}
					cb.utils.alert({
						title: rest.message,
						type: "info",
						duration: "3",
						mask: true,
						onClose: function() {
							//console.log("初始化组织权限");
						},
					});
				});

			viewModel.get("button14jf") && viewModel.get("button14jf").on("click", function(data) {
					// 初始化仓库--单击
					let reqParams = {};
					let urlAPI = "/autodata/WarehouseEntityAuto";
					cb.utils.confirm(
						"确定初始化仓库吗?",
						() => {
							let rest = AutoDataWorkSync(urlAPI, reqParams);
							// console.log(rest)
							if (rest == null) {
								cb.utils.alert("网络异常，请稍后重试");
								return false;
							}
							if (rest.status != 1) {
								cb.utils.alert(rest.message);
								return false;
							}
							cb.utils.alert(rest.message);

						},
						() => {
							//console.log("取消操作");
						}
					);
				});

			viewModel.get("button23yj") && viewModel.get("button23yj").on("click", function(data) {
					// 初始化计量单位--单击
					let reqParams = {};
					let urlAPI = "/autodata/UnitEntityAuto";
					let rest = AutoDataWorkSync(urlAPI, reqParams);
					// console.log(rest)
					if (rest == null) {
						cb.utils.alert("网络异常，请稍后重试");
						return false;
					}
					if (rest.status != 1) {
						cb.utils.alert(rest.message);
						return false;
					}
					cb.utils.alert(rest.message);
				});

			viewModel.get("button33ch") && viewModel.get("button33ch").on("click", function(data) {
					// 初始化物料档案--单击
					let reqParams = {};
					let urlAPI = "/autodata/ProductEntityAuto";
					let rest = AutoDataWorkSync(urlAPI, reqParams);
					// console.log(rest)
					if (rest == null) {
						cb.utils.alert("网络异常，请稍后重试");
						return false;
					}
					if (rest.status != 1) {
						cb.utils.alert(rest.message);
						return false;
					}
					cb.utils.alert(rest.message);

				});

			viewModel.get("button44if") && viewModel.get("button44if").on("click", function(data) {
					// 初始化档案分类--单击
					let reqParams = {};
					let urlAPI = "/autodata/ProductClassAuto";
					let rest = AutoDataWorkSync(urlAPI, reqParams);
					// console.log(rest)
					if (rest == null) {
						cb.utils.alert("网络异常，请稍后重试");
						return false;
					}
					if (rest.status != 1) {
						cb.utils.alert(rest.message);
						return false;
					}
					cb.utils.alert(rest.message);

				});

			viewModel.get("button56mc") && viewModel.get("button56mc").on("click", function(data) {
					// 初始化物料SKU档案--单击
					let reqParams = {};
					let urlAPI = "/autodata/ProductSKUAuto";
					let rest = AutoDataWorkSync(urlAPI, reqParams);
					// console.log(rest)
					if (rest == null) {
						cb.utils.alert("网络异常，请稍后重试");
						return false;
					}
					if (rest.status != 1) {
						cb.utils.alert(rest.message);
						return false;
					}
					cb.utils.alert(rest.message);

				});
				
			viewModel.get("button69ge") && viewModel.get("button69ge").on("click", function(data) {
					// 一键清理基础数据--单击
					let reqParams = {};
					let urlAPI = "/autodata/BaseDataClear";
					cb.utils.confirm(
						"确定清理基础数据吗?",
						() => {
							let rest = AutoDataWorkSync(urlAPI, reqParams);
							// console.log(rest)
							if (rest == null) {
								cb.utils.alert("网络异常，请稍后重试");
								return false;
							}
							if (rest.status != 1) {
								cb.utils.alert(rest.message);
								return false;
							}
							cb.utils.alert(rest.message);

						},
						() => {
							//console.log("取消操作");
						}
					);
				});

			viewModel.get("button85wf") && viewModel.get("button85wf").on("click", function(data) {
					// 添加基础配置--单击
					cb.loader.runCommandLine(
						"bill", {
							billtype: "voucherList",
							billno: "isv_appconfigList",
							params: {},
						},
						viewModel
					);
				});

			viewModel.get("button102dj") && viewModel.get("button102dj").on("click", function(data) {
					// 添加智能货位--单击
					cb.loader.runCommandLine(
						"bill", {
							billtype: "voucherList",
							billno: "dxq_locationList",
							params: {},
						},
						viewModel
					);
				});

			viewModel.get("button120ni") && viewModel.get("button120ni").on("click", function(data) {
					// 添加设备信息--单击
					cb.loader.runCommandLine(
						"bill", {
							billtype: "voucherList",
							billno: "isv_devicelistList",
							params: {},
						},
						viewModel
					);
				});

			viewModel.get("button139yf") && viewModel.get("button139yf").on("click", function(data) {
				// 一键清理基础配置数据--单击
				let reqParams = {};
				let urlAPI = "/autodata/BaseDataClearBusiness";
				cb.utils.confirm(
					"确定清理基础配置数据吗?",
					() => {
						let rest = AutoDataWorkSync(urlAPI, reqParams);
						// console.log(rest)
						if (rest == null) {
							cb.utils.alert("网络异常，请稍后重试");
							return false;
						}
						if (rest.status != 1) {
							cb.utils.alert(rest.message);
							return false;
						}
						cb.utils.alert(rest.message);

					},
					() => {
						//console.log("取消操作");
					}
				);
			});
		},
	};
	try {
		module.exports = GDGY01_isv_appconfigInit_VM_Extend;
	} catch (error) {}
	return GDGY01_isv_appconfigInit_VM_Extend;
});